﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnerCMS.Common;
using WinnerCMS.Data;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 WinnerCMS_Brand 的摘要说明。
    /// </summary>
    public class BrandManage
    {
        private static readonly BrandDal MyDAL = new BrandDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        public void Add(Brand model, ref string strErr)
        {
            if (model.Name.Length == 0)
            {
                strErr = "“品牌名称”不能为空！";
                return;
            }
            if (model.SrcList.Length == 0)
            {
                strErr = "“品牌Logo”不能为空！";
                return;
            }
            if (model.SrcDetail.Length == 0)
            {
                model.SrcDetail = model.SrcList;
            }

            if (model.Title.Length == 0)
            {
                strErr = "“品牌标题”不能为空！";
                return;
            }

            if (model.Id == 0)
            {
                MyDAL.Add(model);
            }
            else
            {
                MyDAL.Edit(model);
            }
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="IDs"></param>
        /// <param name="UpdatePanel1"></param>
        public void Delete(string IDs, UpdatePanel UpdatePanel1)
        {
            if (string.IsNullOrEmpty(IDs))
            {
                MsgBox.Message("至少选择一项。", UpdatePanel1);
            }
            else
            {
                MyDAL.Delete(MyConvert.ConvertToArr(IDs));
            }
        }

        #endregion

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        public Brand GetInfo(int ID)
        {
            return MyDAL.GetInfo(ID);
        }

        #endregion

        /// <summary>
        /// 绑定专题控件
        /// </summary>
        /// <param name="name"></param>
        /// <param name="Type"></param>
        /// <param name="strNewListItem"></param>
        public void BindDDL(ListControl name, string strNewListItem)
        {
            name.DataSource = MyDAL.Bind_DDL();
            name.DataTextField = "Title";
            name.DataValueField = "ID";
            name.DataBind();

            name.Items.Insert(0, new ListItem(strNewListItem, "0"));
        }

        /// <summary>
        /// 绑定分页数据
        /// </summary>
        /// <param name="pp"></param>
        /// <returns></returns>
        public IList<Brand> BindList(PagingParam pp)
        {
            return MyDAL.BindList(pp);
        }

        public IList<Brand> Get18Brands()
        {
            return MyDAL.Get18Brands();
        }

        /// <summary>
        /// 从IDs中取得内容有多少个品牌，每个品牌有多少内容的数量
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public IList<Brand> GetBrandInfoFromIds(string ids)
        {
            return MyDAL.GetBrandInfoFromIds(ids.ToArrInt());
        }
    }
}